<?php
namespace Admin\Controller;
use Admin\Controller\AdminController;
class ArtController extends AdminController {
    public function _initialize(){
        parent::_initialize();
    }
    //空操作
    /*public function _empty(){
        header("HTTP/1.0 404 Not Found");
        $this->display('Public:404');
    }*/
    public function index(){
        $title = I('title');
        if($title){
        	$where['title'] = array('like',"%".$title."%");
        }
        $list = M('Art')->where($where)->select();
        $this->assign('list',$list);
        $this->display();
    }
    public function add(){
        $data["id"] = I('id');
        if(IS_POST){
          
              $data["title"] = I('title');
              $data["content"] = I('content');
              $data["sort"] = I('sort');
              $data['add_time'] =time();
              if($data["id"]){
                  $re = M('Art')->where(array("id"=>$data["id"]))->save($data);
              }else{
                  $re = M('Art')->add($data);
              }
              if($re){
                  $this->success('操作成功',U("Art/index"));
              }else{
                  $this->error('操作失败');
              }
          }else{
          	$list = M('Art')->where(array("id"=>$data["id"]))->find();
          	$this->assign('article',$list);
          	$this->display();
          }
       
         
    	
    }
    public function del(){
    $id = I('id');
		
		$id = intval($id);
		if(!empty($id)){
			$re = M('Art')->where("id={$id}")->delete();
			if($re){
				$this->success('删除成功');
			}else{
				$this->error('删除失败');
			}
		}else{
			$this->error('删除失败');
		}
    }

}